package com.jbm.jbmsupplier.activity.register.mode

import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.utlisclass.HttpNet
import com.jbm.onehome.iface.Login
import rx.Observable
import rx.Observer

/**
 * Created by 家帮忙 on 2017/8/22.
 */
class Regiter_Mode_User_Con : Reginster_UsertInter_Con<String> {
    override fun GainRegisterIntergace(phont: String, validate: String, pwds: String,loginid:String, oclicklist: InterfaceMa<String>) {//注册为施工段
        if (!phont.equals("")||!validate.equals("")||!pwds.equals("")) {

            HttpNet.getInstans().obsevice(Observable.create(Observable.OnSubscribe<Login> { obVersion ->
                obVersion.onNext(HttpNet.getInstans().getOhInter()  .RegistCustomer(Integer.parseInt(loginid), "", "", "", validate, true,phont))
            })).subscribe(object :Observer<Login>{
                override fun onNext(t: Login?) {
                    if (t?.m_code == 200) {
                        //搭桥成功
                     oclicklist.onSuccess(t.login_id.toString(),true)
                    } else if (t?.m_info == "time out") {
                      oclicklist.onSuccess(t.m_info,false)
                        //搭桥超时


                    } else if (t?.m_code == 500) {
                        oclicklist.onSuccess(t.m_info,false)
                        //搭桥失败


                    } else {
                        oclicklist.onSuccess(t!!.m_info,false)

                    }
                }

                override fun onError(e: Throwable?) {
                }

                override fun onCompleted() {
                }

            })





        }


    }

    override fun GainValidateCode(validate: String, oclicklist: InterfaceMa<String>) {
        if (!validate.equals("")) {
            HttpNet.getInstans().obsevice(Observable.create(Observable.OnSubscribe<Login> { obVersion ->
                obVersion.onNext(HttpNet.getInstans().getOhInter().RegistCustomer(0, validate, "", "", "", false,""))
            })).subscribe(object :Observer<Login>{
                override fun onCompleted() {

                }
                override fun onNext(t: Login?) {
                    if (t?.m_code==200){
                        oclicklist.onSuccess(t.login_id.toString(),true)

                    } else if (t?.m_info == "time out") {
                        oclicklist.setError(t.m_info,false)
                        //手机号获取验证码超时

                    } else if (t?.m_code == 500) {
//                        手机号获取验证码失败
                        oclicklist.setError(t.m_info,false)
                    } else {
                        //手机号获取验证码失败
                        oclicklist.setError(t!!.m_info,false)
                    }


                }

                override fun onError(e: Throwable?) {

                    oclicklist.setError("请求接口错误"+e,false)



                }

            })

        }


    }




}